package com.project.export

import org.apache.spark.SparkConf
import org.apache.spark.sql.{SaveMode, SparkSession}

object wordcloud {
  def main(args: Array[String]): Unit = {
      //-:Spark配置对象
      val sparkConf = new SparkConf()
        .setMaster("local[*]")
      //-:sparkSession对象
      val sparkSession = SparkSession
        .builder()
        .config(sparkConf)
        //-:开启hive的支持
        .enableHiveSupport()
        .appName("WorldCloud")
        .getOrCreate()
      //-:读取hive中对应表的内容
      val df_colleges = sparkSession.sql("select * from final_project.dwd_colleges_information where nine_eight_five==1 or two_one_one==1;")
      //-:将读取到的内容导出到MySQL数据库中
      df_colleges.write
        .format("jdbc")
        .option("url","jdbc:mysql://192.168.75.104:3306/finalProject")
        .option("user","root")
        .option("password","123456")
        .option("dbtable","wordcloud")
        .mode(SaveMode.Overwrite)
        .save()
      //-:sparkSession的停止、关闭
      sparkSession.stop()
      sparkSession.close()
  }
}
